<template>
	<view>
		<view v-if="JSON.stringify(address) === '{}'" class="address-button-box">
			<button type="primary" size="mini" @click="chooseAddress">请选择收货地址</button>
		</view>
		
		<view v-else class="address-box" @click="chooseAddress">
			<view class="row1">
				<view class="row1-left">
					<view class="row1-name">
						收货人：{{address.userName}}
					</view>
				</view>
				<view class="row1-right">
					<view class="phone-box">
						电话：{{address.telNumber}}
					</view>
					<uni-icons type="arrowright"></uni-icons>
				</view>
			</view>
			<view class="row2">
				<view class="row2-left">
					<text>收货地址:</text>
				</view>
				<view class="row2-right">
					{{addstr}}
				</view>
			</view>
		</view>
		<image class="address-border" src="../../static/cart_border@2x.png" mode=""></image>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	import badgeMixin from '@/mixins/tabber-badge.js'
	export default {
		mixins:[badgeMixin],
		name:"my-address",
		data() {
			return {
				
			};
		},
		methods:{
			...mapMutations("my_address",['updateAddress']),
			async chooseAddress(){
				const res = await uni.chooseAddress().catch(err=>err)
				if(res.errMsg ==='chooseAddress:ok') {
					this.updateAddress(res)
				}
			},
		},
		computed: {
			...mapState("my_address",['address']),
			...mapGetters("my_address",['addstr'])
		},
	}
</script>

<style lang="scss">
.address-border {
	width: 100%;
	display: block;
	height: 5px;
}
.address-box {
	padding: 20px 0;
}
.address-button-box {
	height: 90px;
	display: flex;
	justify-content: center;
	align-items: center;
}
.row1{
	display: flex;
	justify-content: space-between;
}
.row1-right {
	display: flex;
	justify-content: space-between;
}
.row2 {
	display: flex;
	align-items: center;
	margin-top: 10px;
}
.row2-left {
	text{
		white-space: nowrap;
	}
}
</style>